package cn.diancan.vo.other;

import java.util.List;


/**
 * Bean类 - 分页
 * @author lishuai
 */
public class Pager {
	
	// 排序方式
	public enum OrderType{
		asc, desc
	}
	
	public Pager(Integer pageNumber,Integer pageSize) {
		super();
		if (null != pageNumber && !"".equals(pageNumber)) {
			try {
				Integer pageSizeNum = Integer.valueOf(pageNumber); 
				if (null != pageSizeNum &&  pageSizeNum>0) {
					this.setPageNumber(pageSizeNum);
				} else {
					this.setPageNumber(1);
				}
			} catch (NumberFormatException e) {
				this.setPageNumber(1);
			}
		} else {
			this.setPageNumber(1);
		}
		this.setPageSize(pageSize); 
	}
	

	public Pager() {
		super();
	}

	private Integer pageNumber = 1;// 当前页码
	private Integer pageSize = 10;// 每页记录数
	private Integer totalCount = 0;// 总记录数
	private Integer pageCount = 0;// 总页数
	private String property ="";// 查找属性名称
	private String keyword="";// 查找关键字
	private String orderBy = "id";// 排序字段
	private OrderType orderType = OrderType.desc;// 排序方式
	
	/**
	 * 当前页的数据
	 */
	private List<?> list;// 数据List
	

	public Integer getPageNumber() {
		return pageNumber;
	}

	public void setPageNumber(Integer pageNumber) {
		if (pageNumber==null||pageNumber < 1) {
			pageNumber = 1;
		}
		this.pageNumber = pageNumber;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		if (pageSize < 1) {
			pageSize = 1;
		} else if(pageSize > 500) {
			pageSize = 500;
		}
		this.pageSize = pageSize;
	}
	
	/**
	 * 第一条数据位置
	 * 
	 * @return
	 */
	public int getFirstResult() {
		return (pageNumber - 1) * pageSize;
	}
	
	public Integer getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(Integer totalCount) {
		this.totalCount = totalCount;
	}

	public Integer getPageCount() {
		pageCount = totalCount / pageSize;
		if (totalCount % pageSize > 0) {
			pageCount ++;
		}
		return pageCount;
	}

	public void setPageCount(Integer pageCount) {
		this.pageCount = pageCount;
	}

	public String getProperty() {
		return property;
	}

	public void setProperty(String property) {
		this.property = property;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}
	
	public String getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}
	
	public OrderType getOrderType() {
		return orderType;
	}

	public void setOrderType(OrderType orderType) {
		this.orderType = orderType;
	}

	public List<?> getList() {
		return list;
	}

	public void setList(List<?> list) {
		this.list = list;
	}
}